package com.cloud.learn.config.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class WebContollor {

	
	@Value("${name}")
	String name;
	
	@RequestMapping(value = "name")
	public String name () {
		return name;
	}
	
	@Autowired
	DiscoveryClient client;
	
	@RequestMapping(value = "add", method = RequestMethod.GET)
	public int add (int a,int b) {
		ServiceInstance instance = client.getLocalServiceInstance();
		System.out.println(instance.getHost());
		System.out.println(instance.getServiceId());
		System.out.println(instance.getPort());
		return a+b + 1;
	}
}
